home *** CD-ROM | disk | FTP | other *** search
/ Crack It! / Crack It!.iso / CONTENT / DISKEDIT / SYSRT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-09-09  |  8KB  |  264 lines

  1. {
  2.  ***
  3.  
  4.  SYSRT.PAS
  5.  Initialization and Cleanup Routines
  6.  (C)Copyright Gerard Paul Java 1996
  7.  
  8.  Unit Source File
  9.  
  10.  
  11.  This unit contains routines to initialize the screen and set the proper
  12.  related variables, as well as keyboard-related routines.  This is intended
  13.  to be used for full-screen programs.
  14.  
  15.  ***
  16. }
  17.  
  18. {$A+,B-,F-,I-,N-,R-,S-,V-}
  19.  
  20. unit SysRt;
  21.  
  22. interface
  23.  
  24. type
  25.   PromptType      = string[64];
  26.  
  27. const
  28.   ExtKey             = #0;                        { Extended key prefix. }
  29.  
  30.   F1                 = #59;                       { Special global keys. }
  31.   Esc                = #27;
  32.   Enter              = #13;
  33.  
  34.   UpKey              = #72;
  35.   DownKey            = #80;
  36.   LeftKey            = #75;
  37.   RightKey           = #77;
  38.   PgUpKey            = #73;
  39.   PgDnKey            = #81;
  40.   HomeKey            = #71;
  41.   EndKey             = #79;
  42.   InsKey             = #82;
  43.   DelKey             = #83;
  44.  
  45.   ExitKey            = 'X';
  46.   AltExitKey         = 'Q';
  47.   RetryKey           = 'R';
  48.  
  49.   KeyMarker          = '^';
  50.  
  51.   Null               = '';
  52.   Space              = ' ';
  53.  
  54.   SnowCheckOn        = TRUE;
  55.   SnowCheckOff       = FALSE;
  56.  
  57.   BreakOn            = TRUE;
  58.   BreakOff           = FALSE;
  59.  
  60. function GetKeyNoExt: char;
  61. inline($30/$E4/            { XOR AH,AH }
  62.        $CD/$16);           { INT $16 }
  63. procedure WaitForKeypress;
  64. inline($30/$E4/            { XOR AH,AH }
  65.        $CD/$16);           { INT $16 }
  66. function BIOSEquipList: word;
  67. inline($CD/$11);            { INT $11 }
  68. procedure ScreenInit;
  69. procedure GetInput(var Result: string;lngth: integer;var Signal: boolean);
  70. procedure InputBox(X1,Y1,X2,Y2: byte;
  71.                    Attr: byte;
  72.                    Prompt: PromptType; FieldLength: byte;
  73.                    var Result: string;var Signal: boolean);
  74. procedure Beep(Freq,Dur: word);
  75. procedure TerminateProg(ErrorLevel: byte);
  76.  
  77. implementation
  78.  
  79. uses
  80.   Crt,
  81.   ScreenRt;
  82.  
  83. type
  84.   OrigCursorType        = object
  85.                             ScanLines: word;
  86.                             procedure Save;
  87.                             procedure Restore;
  88.                           end;
  89.  
  90.   OrigScreenSettingsType = object
  91.                              OrigMode        : word;
  92.                              OrigActivePage  : byte;
  93.                              procedure Save;
  94.                              procedure Restore;
  95.                            end;
  96.  
  97. var
  98.   OrigCursor        : OrigCursorType;
  99.   OrigScreenSettings: OrigScreenSettingsType;
  100.  
  101.  
  102. {---------------------------------------------------------------------------
  103.  OrigCursorType.Save: Saves the cursor's settings.
  104.  ---------------------------------------------------------------------------}
  105.  
  106. procedure OrigCursorType.Save;
  107. begin
  108.   inline($B4/$03/             { MOV       AH,3 }
  109.          $CD/$10/             { INT       $10 }
  110.          $C4/$7E/$06/         { LES       DI,Self }
  111.          $26/$89/$0D);        { MOV       ScanLines,CX }
  112. end;
  113.  
  114.  
  115. {---------------------------------------------------------------------------
  116.  OrigCursorType.Restore: Restores the hidden cursor.
  117.  ---------------------------------------------------------------------------}
  118.  
  119. procedure OrigCursorType.Restore;
  120. begin
  121.   SetCursor(ScanLines);                    { Reset to original. }
  122. end;
  123.  
  124.  
  125. {---------------------------------------------------------------------------
  126.  OrigScreenSettings.Save: Saves the current screen mode and active page in
  127.  the object variable.
  128.  ---------------------------------------------------------------------------}
  129.  
  130. procedure OrigScreenSettingsType.Save;
  131. begin { proc }
  132.   OrigMode := LastMode;                    { Save screen mode. }
  133.  
  134.   inline($B4/$0F/                          { MOV  AH,15 }
  135.          $CD/$10/                          { INT  $10 }
  136.          $C4/$7E/$06/                      { LES  DI,Self }
  137.          $26/$88/$7D/$02);                 { MOV  OrigActivePage,BH }
  138. end; { proc }
  139.  
  140.  
  141. {---------------------------------------------------------------------------
  142.  OrigScreenSettings.Restore: Restores the screen to its original mode found
  143.  at startup.
  144.  ---------------------------------------------------------------------------}
  145.  
  146. procedure OrigScreenSettingsType.Restore;
  147. begin
  148.   TextMode(OrigMode);                      { Reset to original mode. }
  149.  
  150.   inline($B4/$05/                          { MOV   AH,05 }
  151.          $C4/$7E/$06/                      { LES   DI,Self }
  152.          $26/$8A/$45/$02/                  { MOV   AL,OrigActivePage }
  153.          $CD/$10);                         { INT   $10 }
  154. end;
  155.  
  156.  
  157. {--------------------------------------------------------------------------
  158.  ScreenInit: Sets the screen and snow-checking variable  and sets the
  159.  proper values used by the screen save/restore routines.
  160.  --------------------------------------------------------------------------}
  161.  
  162. procedure ScreenInit;
  163. begin
  164.   OrigScreenSettings.Save;
  165.   OrigCursor.Save;
  166.  
  167.   if Lo(LastMode) = Mono then                 { Select proper screen mode. }
  168.     ClrScr
  169.   else
  170.     TextMode(CO80);
  171.  
  172.   SetCursor($FFFF);                           { Hide cursor. }
  173.  
  174.   Delay(100);                        { Allow screen settling time. }
  175. end;
  176.  
  177.  
  178. procedure GetInput(var Result: string;lngth: integer;var Signal: boolean);
  179. var
  180.   charac: char;
  181.   savecsr: byte;
  182.  
  183. begin
  184.   Signal := FALSE;
  185.   Result:=Null;
  186.  
  187.   savecsr:=wherex;
  188.   Write(StringOf(Space,Lngth));
  189.  
  190.   gotoxy(savecsr,wherey);
  191.   SetCursor($0607);
  192.   repeat
  193.     charac:=UpCase(ReadKey);
  194.  
  195.     case charac of
  196.        chr(8): begin
  197.          if (length(Result)>0) then
  198.            begin
  199.              Write(#8,Space,#8);
  200.              Result:=copy(Result,1,length(Result)-1);
  201.            end;
  202.         end;
  203.    Esc        : Signal := TRUE;
  204.  else
  205.       if (length(Result)<lngth) and (ord(charac)>=32) then
  206.     begin
  207.       write(charac);
  208.       Result:=Result+charac;
  209.     end;
  210.       end;
  211.    until (charac = Enter) or (charac = Esc);
  212.    SetCursor($FFFF);
  213. end;
  214.  
  215.  
  216. {----------------------------------------------------------------------------
  217.  InputBox:  Displays a box containing an input field where a string of a
  218.  speficied length is to be entered.  Signal returns TRUE if Esc was pressed.
  219.  ----------------------------------------------------------------------------}
  220.  
  221. procedure InputBox(X1,Y1,X2,Y2: byte;
  222.                    Attr: byte;
  223.                    Prompt: PromptType; FieldLength: byte;
  224.                    var Result: string;var Signal: boolean);
  225. begin
  226.   Window(1,1,80,25);                       { Revert to whole screen. }
  227.   TextAttr := BoxAttr;DrawBox(X1,Y1,X2,Y2,DoubleLine);
  228.   Window(X1+2,Y1+1,X2-1,Y2-1);
  229.   TextAttr := TextNormAttr;
  230.   Writeln;
  231.   Writeln(Prompt);
  232.   Writeln;
  233.   TextAttr := Attr;
  234.   GetInput(Result,FieldLength,Signal);
  235. end;
  236.  
  237.  
  238. {---------------------------------------------------------------------------
  239.  Beep: Beeps the speaker.
  240.  ---------------------------------------------------------------------------}
  241.  
  242. procedure Beep;
  243. begin
  244.   Sound(Freq);
  245.   Delay(Dur);
  246.   NoSound;
  247. end;
  248.  
  249.  
  250. {---------------------------------------------------------------------------
  251.  TerminateProg: Clears the screen, resets the video mode, and terminates the
  252.  program.
  253.  ---------------------------------------------------------------------------}
  254.  
  255. procedure TerminateProg(ErrorLevel: byte);
  256. begin { proc }
  257.   OrigScreenSettings.Restore;
  258.   OrigCursor.Restore;
  259.   Delay(100);
  260.   Halt(ErrorLevel);                        { Terminate w/ ERRORLEVEL code. }
  261. end; { proc }
  262.  
  263. end.
  264.